package reese.think_in_java.java_21_thread;

import java.util.concurrent.TimeUnit;

/**
 * ***********************************************************
 *
 * @类名 : reese.think_in_java.java_21_thread.类名
 * @DESCRIPTION : 这家伙太懒啥都没写
 * @AUTHOR :  一个风情万种的男子
 * @DATE : 2016/5/28
 * ***********************************************************
 */

class Daemon implements Runnable {

    private Thread[] t = new Thread[10];
    public void run() {
        for (int i=0;i<t.length;i++){
            t[i] = new Thread(new DaemonSpawn());
            t[i].start();
            System.out.println("DaemonSpawn " + i + " started ,");

        }
        for (int i=0;i<t.length;i++){
            System.out.println("t[" + i + "].isDaemon() = " + t[i].isDaemon() + ", ");
        }
        while (true){
            Thread.yield();
        }



    }
}





/**
 * Spawn : 产卵的意思
 */
class DaemonSpawn implements Runnable {

    public void run() {
        while (true){
            Thread.yield();
        }
    }
}


public class Daemons {

    public static void main(String[] args) throws InterruptedException {
        Thread d = new Thread(new Daemon());
        d.setDaemon(true);
        d.start();
        System.out.println("isDaemon ? " + d.isDaemon());

        // allow the Daemon threads to finish their startup processes
        TimeUnit.MILLISECONDS.sleep(100000);
    }
}
